package com.it.rabbitmqwithjiang.Listener;


import com.it.rabbitmqwithjiang.Dao.MessageDao;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class FanoutListener1 {
	@RabbitListener(queues = "fanoutqueue1")
	public void FanoutMessage(MessageDao messageDao, Channel channel, Message message) throws IOException {
		//确认消息
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		//channel对象重新发送消息到队尾
		channel.basicPublish(message.getMessageProperties().getReceivedExchange(),
				message.getMessageProperties().getReceivedRoutingKey(), true,null,
				messageDao.getMessage().getBytes("UTF8"));
		System.out.println("订阅者fanoutqueue1收到消息"+ messageDao.toString());
	}
}
